package com.feihong.txgw.adapter.Holder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.feihong.txgw.R;
import com.feihong.txgw.model.bean.user.SortModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by PVer on 2017/8/24.
 */

public class HotCityViewAdapter extends BaseAdapter{
    private Context mContext;
    List<SortModel.DataBean.HotCityBean> mHotCityBean;
    public HotCityViewAdapter(Context context){
        mContext = context;
        mHotCityBean = new ArrayList<>();
    }
    public void setData(List<SortModel.DataBean.HotCityBean> hotCityBean){
        mHotCityBean = hotCityBean;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mHotCityBean.size();
    }

    @Override
    public Object getItem(int position) {
        return mHotCityBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.hot_city_item_layout,parent,false);
            viewHolder = new ViewHolder();
            convertView.setTag(viewHolder);
            viewHolder.initView(convertView);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
            viewHolder.initData(position);
            return convertView;
    }
    class ViewHolder{
        TextView tv;
        void initView(View convertView){
            tv = (TextView) convertView.findViewById(R.id.hot_city_item_tv);
        }

        void initData(int index){
            tv.setText(mHotCityBean.get(index).getRegion_name());
        }
    }
}
